<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'base.item.class.php');

class ProductFieldValueBase extends BaseItemBase {
	
	//constructor
	function ProductFieldValueBase() {
		parent::BaseItemBase();
		
		$this->_table_owner_usable = false;
		
		$this->table = 'pp_products_values';
		$this->prefix = 'values_';
		
		$this->filter_fields = array('pid:=', 'fid:=');
		$this->filter_map = array('pid' => 'pid:=', 'fid' => 'fid:=');
	}
	
	//methods
	function getItemsDetail($filter = '', $check = 0, $limit = true) {
		$values = $this->getItems($filter, $check, $limit);
		$ids = $this->getListKey($values, 'fid');
		//
		$items = array();
		if( is_array($ids) ) {
			$ids = array_unique($ids);
			include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/product/product.field.class.php');
			$mObj = new ProductFieldBase();
			$mObj->format = true;
			
			$items = $mObj->getItems(array('ids' => $ids), -1, false);
			$items = $mObj->setListKey($items, 'id');
		}
		//
		$detail = array();
		for($i=0, $n=sizeof($values); $i<$n; $i++) {
			$detail[] = array('item' => $items[$values[$i]['fid']], 'value' => $values[$i]);
		}
		
		return $detail;
	}
}
//
?>